/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package app.utils;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author DangThanh
 */
public class HashMD5 {

    public HashMD5() {
    }

    /***
     * Hash MD5 for password
     * @param password
     * @return String
     */
    public String hashMD5(String password) {
        byte[] hash;
        String temp = "";
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            hash = md.digest(password.getBytes("UTF-8"));
            for (int i = 0; i < hash.length; i++) {
                temp += Byte.toString(hash[i]);
            }
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(HashMD5.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(HashMD5.class.getName()).log(Level.SEVERE, null, ex);
        }
        return temp;
    }
}
